<?php
include_once 'basepath.php';
if(!isset($message))
{
	$message="";
}

//print_r($edit);
$typeswith=-1;
if(isset($edit)&&isset($forfaits))
	{
		if(count($forfaits)>0)
		$typeswith=$edit[0]["forfaittype"];
	}
//print_r($forfaits);
$lsitinfoforfait=array();
if(isset($forfaits)){
if(count($forfaits)>0)
	{
		foreach ($forfaits as $ff)
		{
			$indicateur=$ff["chambretype"];
			$lsitinfoforfait["$indicateur"]=array("title"=>$ff["title"],"priceadult"=>$ff["priceadult"],"pricechild"=>$ff["pricechild"]);
		}	
	}
//print_r($lsitinfoforfait);
}	
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<link rel="stylesheet" href="<?php echo $bpath;?>/css/reset.css" />
<link rel="stylesheet" href="<?php echo $bpath;?>/css/text.css" />
<link rel="stylesheet" href="<?php echo $bpath;?>/css/960_24_col.css" />
 <link rel="stylesheet" href="<?php echo $bpath;?>/css/jquery-ui-1.8.21.custom.css" />
 <link rel="stylesheet" href="<?php echo $bpath;?>/css/style.css" />
 <link rel="stylesheet" href="<?php echo $bpath;?>/css/faary.css" type="text/css" />
 <script type="text/javascript" src="<?php echo $bpath;?>/js/jquery-1.7.2.min.js"></script>
 <script type="text/javascript" src="<?php echo $bpath;?>/js/jquery-ui-1.8.21.custom.min.js"></script>
<script type="text/javascript" src="<?php echo $bpath;?>/js/scripts.js"></script>
 <script type="text/javascript" src="<?php echo $bpath;?>/js/jquery.validate.js"></script>
<script>
	$(function(){
		  $.validator.addMethod(
			        "regex",
			        function (value, element, regexp) {
			        	    var re = new RegExp(regexp);
			                return this.optional(element) || re.test(value);
			            },
			            "Please check your input."
			        );
$(".formtour").validate({
		submitHandler: function(form){ form.submit() },
		 onfocusout:  function(element) { $(element).valid(); },

		rules: {
			
			TourName: {
				required: true,
				minlength: 8
			},
		
			
			TourCode: {
     		 required: true,
   			},

   			Date: {
     		 required: true,
   			},
   			Description: {
     		 required: true,
   			},
   			fixedprice:{
   				required: true, regex: "^[0-9]+\.[0-9]{2}$"	
   			}
		},
		
		messages: {
			TourName: "Enter Tour Name (at least 8 caracter)",
			TourCode: "TourCode no complet",
			Date:"Enter Date",
			Description:"Enter Your Description",
			fixedprice:"Enter price amout(XXX.XX) "
			}
		
});
	$( "#Date" ).datepicker({ dateFormat: "yy-mm-dd" });

	
// slect forfait
//en page loading
var switchtype=<?php echo $typeswith; ?>;
if(switchtype==-1)
	{
		$(".chambreyesno").removeAttr("checked");
		$(".lforfait").css("display","none");
	}
if(switchtype==1)
{
	$(".chambreyesno").removeAttr("checked");
	$(".chambreyesno[value=1]").attr("checked","");
	$(".lforfait").css("display","none");
	$(".forfait1,.forfait2,.forfait3,.forfait4").css("display","block");
	
}

if(switchtype==0)
{
	$(".chambreyesno").removeAttr("checked");
	$(".chambreyesno[value=0]").attr("checked","");
	$(".lforfait").css("display","none");
	$(".forfait0").css("display","block");
	
}
	$(".chambreyesno").click(function(){
			var type=$(this).val();
			if(type==0)
			{
				$(".lforfait").css("display","none");
				$(".forfait0").css("display","block");
				
			}

			if(type==1)
			{
				$(".lforfait").css("display","none");
				$(".forfait1,.forfait2,.forfait3,.forfait4").css("display","block");
				
			}			
		})

	})
</script>
</head>

<body>
	<script type="text/javascript">
<!--
	function isEmailValid(email){
		var e = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
		return e.test(email);
	}
	/*
	function sendForm(){
		
		
		jQuery("#imessageOK, #imessageERROR").hide();
		jQuery(".required").removeClass("required");
		if(jQuery("#TourName").val()==""){jQuery("#TourName").addClass("required");window.scroll(0,0);return false;}if(jQuery("#TourCode").val()==""){jQuery("#TourCode").addClass("required");window.scroll(0,0);return false;}if(jQuery("#Date").val()==""){jQuery("#Date").addClass("required");window.scroll(0,0);return false;}if(jQuery("#Description").val()==""){jQuery("#Description").addClass("required");window.scroll(0,0);return false;}jQuery("#SendaMessage").val("Please Wait...");		var AddDetails; AddDetails+="&TourName="+encodeURIComponent(jQuery("#TourName").val());AddDetails+="&TourCode="+encodeURIComponent(jQuery("#TourCode").val());AddDetails+="&Date="+encodeURIComponent(jQuery("#Date").val());AddDetails+="&Description="+encodeURIComponent(jQuery("#Description").val());		
		alert("Add sending function here...\n\nOr become FAARY member to download full package!")	}

*/
-->
</script>
	<div class="principal container_24">
		
		<!--logo-->
		<div class="logo grid_24">
			<div class="grid_1">&nbsp;</div>
			<div class="grid_4 logoimage"><img src="<?php echo $bpath;?>/img/logo.png" height="90"></div>
			<div class="logout grid_5"><a href="index.php?loginprocess/loginout"><img src="<?php echo $bpath;?>/img/bt_logout.jpg"/></a></div>
		</div><!-- end logo-->
		
		<!--menupricipal-->
		<div class="menuprincipal grid_24">
			<div class="menuprincipal grid_24">
			<a class="yearlist " href="index.php?liste/listtour">Back to List </a>
		</div>
		</div>
		<!-- end menupricipal-->
				
			<div class="descprincipal grid_22">
				description
				<br/>
				<h3><?php echo $message;?></h3>
			</div>
			
			<div class="grid_24 listcontent">
				<h1>CREATE OR EDIT A TOUR</h1>
				<div class="grid_22 list">
<?php if(isset($edit)!=true) {?>				
<form method="post" action="index.php?add/actionAdd/tour"  class="iform grid_18 formtour" onSubmit="return false">
<?php }else{?>
<form method="post" action="index.php?edit/actionedit/tour"  class="iform grid_18 formtour" onSubmit="return false">
<input type="hidden" name="idtour"  value="<?php echo $edit[0]["idtours"]; ?>" />
<?php }?>
<div id="imessageOK">Thank you! Message Sent!</div>
<div id="imessageERROR">ERROR: Message Not Sent!</div>
<ul class="">
<li class="iheader">CREATE OR EDIT A TOUR</li>
<li><label for="TourName">*Tour Name</label><input class="itext" type="text" name="TourName" id="TourName" value="<?php echo (isset($edit))? $edit[0]["name"]:""; ?>" /></li>
<li><label for="TourCode">*Tour Code</label><input class="itext" type="text" name="TourCode" id="TourCode" value="<?php echo (isset($edit))? $edit[0]["code"]:""; ?>"/></li>
<li><label for="Date">*Date</label><input class="itext" type="text" name="Date" id="Date"  value="<?php echo (isset($edit))? $edit[0]["date"]:""; ?>"/></li>
<li><label for="time">*Depart Time</label><input class="itext" type="text" name="time" id="time"  value="<?php echo (isset($edit))? $edit[0]["time"]:""; ?>"/></li>
<li><label for="lieu">*Depart Place</label><input class="itext" type="text" name="lieu" id="lieu"  value="<?php echo (isset($edit))? $edit[0]["lieu"]:""; ?>"/></li>
<li><label for="Price">*Forfait Type</label><input class="itext chambreyesno" type="radio" name="chambreyesno"  style="width:20px" value="0"/>One day Without Chambre</li>
<li><label for="Price">&nbsp;</label><input class="itext chambreyesno" type="radio" name="chambreyesno" style="width:20px" value="1"/>More days With Chambre</li>
<?php if(array_key_exists("0",$lsitinfoforfait)){?>
<li class="lforfait forfait0">
<label for="Description">Forait 0</label>
Title:<input class="itext forfait"  type="text" name="c0ttle" id="c0ttle" value="<?php echo $lsitinfoforfait["0"]["title"];?>"/>
Adult:$<input class="itext forfait" type="text" name="c0adult" id="c0adult" value="<?php echo $lsitinfoforfait["0"]["priceadult"];?>"/>
Child:$<input class="itext forfait" type="text forfait" name="c0child" id="c0child" value="<?php echo $lsitinfoforfait["0"]["pricechild"];?>"/>
</li> 
<?php }else{?>
<li class="lforfait forfait0">
<label for="Description">Forait 0</label>
Title:<input class="itext forfait"  type="text" name="c0ttle" id="c0ttle" value=""/>
Adult:$<input class="itext forfait" type="text" name="c0adult" id="c0adult" value="0.00"/>
Child:$<input class="itext forfait" type="text forfait" name="c0child" id="c0child" value="0.00"/>
</li> 
<?php }?>


<?php if(array_key_exists("1",$lsitinfoforfait)){?>
<li class="lforfait forfait1">
<label for="Description">Forait S</label>
Title:<input class="itext forfait" type="text" name="c1ttle" id="c1ttle" value="<?php echo $lsitinfoforfait["1"]["title"];?>"/>
Adult:$<input class="itext forfait" type="text" name="c1adult" id="c1adult" value="<?php echo $lsitinfoforfait["1"]["priceadult"];?>"/>
Child:$<input class="itext forfait" type="text" name="c1child" id="c1child" value="<?php echo $lsitinfoforfait["1"]["pricechild"];?>"/>
</li> 
<?php }else{?>
<li class="lforfait forfait1">
<label for="Description">Forait 0</label>
Title:<input class="itext forfait"  type="text" name="c1ttle" id="c0ttle" value=""/>
Adult:$<input class="itext forfait" type="text" name="c1adult" id="c0adult" value="0.00"/>
Child:$<input class="itext forfait" type="text forfait" name="c1child" id="c0child" value="0.00"/>
</li> 
<?php }?>

<?php if(array_key_exists("2",$lsitinfoforfait)){?>
<li class="lforfait forfait2">
<label for="Description">Forait D</label>
Title:<input class="itext forfait" type="text" name="c2ttle" id="c2ttle" value="<?php echo $lsitinfoforfait["2"]["title"];?>"/>
Adult:$<input class="itext forfait" type="text" name="c2adult" id="c2adult" value="<?php echo $lsitinfoforfait["2"]["priceadult"];?>""/>
Child:$<input class="itext forfait" type="text" name="c2child" id="c2child" value="<?php echo $lsitinfoforfait["2"]["pricechild"];?>"/>
</li> 
<?php }else{?>
<li class="lforfait forfait2">
<label for="Description">Forait D</label>
Title:<input class="itext forfait" type="text" name="c2ttle" id="c2ttle" value=""/>
Adult:$<input class="itext forfait" type="text" name="c2adult" id="c2adult" value="0.00"/>
Child:$<input class="itext forfait" type="text" name="c2child" id="c2child" value="0.00"/>
</li> 
<?php }?>


<?php if(array_key_exists("3",$lsitinfoforfait)){?>
<li class="lforfait forfait3">
<label for="Description">Forait T</label>
Title:<input class="itext forfait" type="text" name="c3ttle" id="c3ttle" value="<?php echo $lsitinfoforfait["3"]["title"];?>"/>
Adult:$<input class="itext forfait" type="text" name="c3adult" id="c3adult" value="<?php echo $lsitinfoforfait["3"]["priceadult"];?>"/>
Child:$<input class="itext forfait" type="text" name="c3child" id="c3child" value="<?php echo $lsitinfoforfait["3"]["pricechild"];?>"/>
</li> 
<?php }else{?>
<li class="lforfait forfait3">
<label for="Description">Forait T</label>
Title:<input class="itext forfait" type="text" name="c3ttle" id="c3ttle" value=""/>
Adult:$<input class="itext forfait" type="text" name="c3adult" id="c3adult" value="0.00"/>
Child:$<input class="itext forfait" type="text" name="c3child" id="c3child" value="0.00"/>
</li> 
<?php }?>

<?php if(array_key_exists("4",$lsitinfoforfait)){?>
<li class="lforfait forfait4">
Title:<input class="itext forfait" type="text" name="c4ttle" id="c4ttle" value="<?php echo $lsitinfoforfait["4"]["title"];?>"/>
<label for="Description">Forait Q</label>
Adult:$<input class="itext forfait" type="text" name="c4adult" id="c4adult" value="<?php echo $lsitinfoforfait["4"]["priceadult"];?>"/>
Child:$<input class="itext forfait" type="text" name="c4child" id="c4child" value="<?php echo $lsitinfoforfait["4"]["pricechild"];?>"/>
</li> 
<?php }else{ ?>

<li class="lforfait forfait4">
Title:<input class="itext forfait" type="text" name="c4ttle" id="c4ttle" value=""/>
<label for="Description">Forait Q</label>
Adult:$<input class="itext forfait" type="text" name="c4adult" id="c4adult" value="0.00"/>
Child:$<input class="itext forfait" type="text" name="c4child" id="c4child" value="0.00"/>
</li>
<?php }?>

<li><label for="Description">*Description</label><textarea class="itextarea" name="Description" id="Description" value=""><?php echo (isset($edit))? $edit[0]["description"]:""; ?></textarea></li>
<li><label>&nbsp;</label><input type="submit" class="ibutton"  name="SendaMessage" id="SendaMessage" value="Submit" /></li>
</ul></form>
				</div>
			</div>
		
	</div><!--end principal-->
</body>
</html>